package com;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.io.File;

@WebServlet(urlPatterns = "/headshow")
public class HeadShow extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String header= (String) req.getSession().getAttribute("img");
        System.out.println("获取用户头像的名称："+header);
        //头像的File对象d
        java.io.File file = new File("D:\\uploader\\" + header);
        try (
                InputStream in = new FileInputStream(file);
                OutputStream out = resp.getOutputStream();
        ) {
            IOUtils.copy(in, out);
        }
    }
}
